//
//  DepthMap.m
//  Depthmap
//
//  Created by 沙智超 on 2018/3/22.
//  Copyright © 2018年 沙智超. All rights reserved.
//

#import "DepthMap.h"

@implementation DepthMap


- (void)drawRect:(CGRect)rect {
    
    CGRect rect1 = CGRectMake(0, 100, self.frame.size.width, 200);
    
    CGContextRef context1 = UIGraphicsGetCurrentContext();
    
    CGContextClearRect(context1, rect1);
    CGContextSetFillColorWithColor(context1, [UIColor orangeColor].CGColor);
    CGContextFillRect(context1, rect);
    self.context = context1;
    
    CGFloat user = (1300-50)/(200-0);
    
    
    NSArray *buyArray = @[@[@"0",@"980"],@[@"20",@"900"],@[@"30",@"930"],@[@"40",@"900"],@[@"50",@"888"],@[@"60",@"850"],@[@"70",@"700"],@[@"80",@"600"],@[@"90",@"500"],@[@"100",@"300"],@[@"110",@"267"],@[@"120",@"260"],@[@"130",@"289"],@[@"140",@"160"],@[@"150",@"130"],@[@"160",@"110"],@[@"170",@"120"],@[@"180",@"60"],@[@"190",@"30"],@[@"200",@"50"],@[@"200",@"0"]];
    NSArray *sellArray = @[@[@"21",@"20"],@[@"22",@"80"],@[@"23",@"200"],@[@"24",@"250"],@[@"25",@"300"],@[@"26",@"350"],@[@"27",@"400"],@[@"28",@"420"],@[@"29",@"400"],@[@"30",@"420"],@[@"31",@"467"],@[@"32",@"560"],@[@"33",@"599"],@[@"34",@"680"],@[@"35",@"640"],@[@"36",@"700"],@[@"37",@"710"],@[@"38",@"710"],@[@"39",@"730"],@[@"40",@"850"]];
    
    
    //CGContextSetLineCap(self.context, kCGLineCapRound);//设置线的起始端的样式
    //CGContextSetLineJoin(self.context, kCGLineJoinRound);//设置线的连接样式
    
    
    UIColor *lineColor = [UIColor redColor];
    
    CGContextSetStrokeColorWithColor(self.context, lineColor.CGColor);
    
    CGContextSetLineWidth(self.context, 0.8);
    
    CGPoint firstPoint = CGPointMake([buyArray.firstObject[0] doubleValue], [buyArray.firstObject[1] doubleValue]);
    //    NSAssert(!isnan(firstPoint.x) && !isnan(firstPoint.y), @"出现NAN值：MA画线");
    CGContextMoveToPoint(self.context, firstPoint.x,firstPoint.y);
    
        for (int i=0; i<buyArray.count; i++) {
    
            CGPoint point = CGPointMake([buyArray[i][0] doubleValue], [buyArray[i][1] doubleValue]);
            CGContextAddLineToPoint(self.context, point.x, ABS(200- (point.y-0)/user));
          
      }
//    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
//    CGFloat colors[] =
//
//    {
//
//        1,1,1, 1.00,
//
//        0,0,0, 1.00,
//
//    };
//
//
//    CGGradientRef gradient = CGGradientCreateWithColorComponents
//
//    (rgb, colors, NULL,sizeof(colors)/(sizeof(colors[0])*4));
//    CGContextDrawLinearGradient(self.context, gradient,CGPointMake
//
//                                (0,980) ,CGPointMake(200,0),
//
//                                kCGGradientDrawsBeforeStartLocation);
    //    for (int j=0; j<sellArray.count; j++) {
    //
    //        UIColor *lineColor = [UIColor blueColor];
    //
    //        CGContextSetStrokeColorWithColor(self.context, lineColor.CGColor);
    //
    //        CGContextSetLineWidth(self.context, 0.8);
    //
    //        CGPoint point = CGPointMake([sellArray[j][0] doubleValue], [sellArray[j][1] doubleValue]);
    //        CGContextAddLineToPoint(self.context, point.x, point.y);
    //
    //
    //    }
    
    CGContextStrokePath(self.context);
   //hhhhh
   //sss
}


@end
